﻿Imports BE.BE

Namespace DAL
    Public Class DAL_Nota

        Shared Sub guardar(pNota As Nota_BE, pId As Integer)

            Try
                pNota.Id = Helper_DAL.ObtenerProximoId("nota")
            Catch ex As Exception
                Throw ex
            End Try


            Dim strcomm As String = "insert into nota (id_nota, id_expediente, descripcion, texto) values " & _
                                     "(" & pNota.Id & "," & pId & ",'" & pNota.Descripcion & "','" & pNota.Texto & "')"

            Try
                Helper_DAL.ExecuteNonQuery(strcomm)
            Catch ex As Exception
                Throw ex
            End Try

        End Sub

        Shared Sub modificar(pNota As Nota_BE)


        End Sub

        Shared Sub borrar(pId As Integer)
            Dim strcomm As String = "delete from nota where id_expediente = " & pId

            Try
                Helper_DAL.ExecuteNonQuery(strcomm)
            Catch ex As Exception
                Throw ex
            End Try


        End Sub

        Shared Function obtenerXExpedente(pId As Integer) As List(Of Nota_BE)

            Dim strcomm As String = "select id_nota, id_expediente, Texto, Descripcion from nota where id_expediente = " & pId
            Dim mDs As New DataSet
            Dim mLista As New List(Of Nota_BE)

            Try
                mDs = Helper_DAL.ExecuteDataset(strcomm)

                If mDs.Tables(0).Rows.Count > 0 Then

                    For Each dr As DataRow In mDs.Tables(0).Rows
                        Dim mNota As New Nota_BE

                        mNota.Id = dr.Item(0)
                        mNota.Descripcion = dr.Item(3).ToString
                        mNota.Texto = dr.Item(2).ToString


                        mLista.Add(mNota)
                    Next



                End If

                Return mLista


            Catch ex As Exception
                Throw ex
            End Try


        End Function

    End Class
End Namespace


